# 涂色抢地盘游戏 - 后端启动脚本
param(
    [string]$Mode = "normal"  # normal, migrate, seed, full
)

Write-Host "🎯 涂色抢地盘游戏 - 后端启动工具" -ForegroundColor Cyan
Write-Host "================================================" -ForegroundColor Cyan

# 设置环境变量
switch ($Mode.ToLower()) {
    "normal" {
        Write-Host "🚀 正常启动模式" -ForegroundColor Green
        Write-Host "   - 跳过数据库迁移" -ForegroundColor White
        Write-Host "   - 跳过种子数据" -ForegroundColor White
        $env:FORCE_MIGRATION = "false"
        $env:FORCE_SEED = "false"
    }
    
    "migrate" {
        Write-Host "🔄 迁移模式" -ForegroundColor Yellow
        Write-Host "   - 强制应用数据库迁移" -ForegroundColor White
        Write-Host "   - 跳过种子数据" -ForegroundColor White
        $env:FORCE_MIGRATION = "true"
        $env:FORCE_SEED = "false"
    }
    
    "seed" {
        Write-Host "🌱 种子数据模式" -ForegroundColor Yellow
        Write-Host "   - 跳过数据库迁移" -ForegroundColor White
        Write-Host "   - 强制添加种子数据" -ForegroundColor White
        $env:FORCE_MIGRATION = "false"
        $env:FORCE_SEED = "true"
    }
    
    "full" {
        Write-Host "🔧 完整初始化模式" -ForegroundColor Red
        Write-Host "   - 强制应用数据库迁移" -ForegroundColor White
        Write-Host "   - 强制添加种子数据" -ForegroundColor White
        $env:FORCE_MIGRATION = "true"
        $env:FORCE_SEED = "true"
    }
    
    default {
        Write-Host "❌ 未知的启动模式: $Mode" -ForegroundColor Red
        Write-Host "可用模式:" -ForegroundColor Yellow
        Write-Host "  - normal: 正常启动（推荐）" -ForegroundColor White
        Write-Host "  - migrate: 仅迁移数据库" -ForegroundColor White
        Write-Host "  - seed: 仅添加种子数据" -ForegroundColor White
        Write-Host "  - full: 完整初始化" -ForegroundColor White
        Write-Host ""
        Write-Host "示例:" -ForegroundColor Cyan
        Write-Host "  .\start-backend.ps1" -ForegroundColor White
        Write-Host "  .\start-backend.ps1 -Mode migrate" -ForegroundColor White
        exit 1
    }
}

Write-Host ""
Write-Host "🚀 启动后端服务..." -ForegroundColor Green
Write-Host "按 Ctrl+C 停止服务" -ForegroundColor Yellow
Write-Host ""

# 启动后端服务
dotnet run --project src/TerritoryGame.API
